{$R-}

(*
	recvSPort(port number) -- Return a character from the serial port.
	By Harry Chesley.  DO NOT call the author!  Contact Apple Developer 
	Support on AppleLink "MacDTS" or on MCI "MacTech".

	ŠApple Computer, Inc. 1987
	All Rights Reserved.

	To compile and link this file using Macintosh Programmer's Workshop,

	pascal -w recvPort.p
	link -m ENTRYPOINT -o HyperCommands -rt XFCN=1 -sn Main=recvSPort recvPort.p.o "{MPW}"Libraries:interface.o
	
*)

{$S recvSPort } 	{ Segment name must be the same as the command name. }

unit DummyUnit;

interface

uses MemTypes, QuickDraw, OSIntf, HyperXCmd;

procedure EntryPoint(paramPtr: XCmdPtr);
	
implementation

type

Str31 = String[31];

procedure recvSPort(paramPtr: XCmdPtr); forward;

procedure EntryPoint(paramPtr: XCmdPtr);

	begin
		recvSPort(paramPtr);
	end;

procedure recvSPort(paramPtr: XCmdPtr);

	var portNumber: integer;
		inPort: integer;
		str: Str255;
		l: longInt;

	{$I XCmdGlue.inc}

	procedure Fail(errMsg: Str255); { set theResult and quit }
		begin
			paramPtr^.returnValue := PasToZero(errMsg);
			exit(recvSPort);
		end;

	begin
		if paramPtr^.paramCount <> 1 then Fail('parameter count is not 1');

		ZeroToPas(paramPtr^.params[1]^,str);		{ First parameter is port number. }
		portNumber := StrToNum(str);
		if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');

		if portNumber = 1 then inPort := -6
		else inPort := -8;
		l := 1;
		str[0] := chr(1);
		if FSRead(inPort,l,Ptr(ord4(@str)+1)) <> noErr then Fail('FSRead failed');
		if l <> 1 then str[0] := chr(0);
		paramPtr^.returnValue := PasToZero(str);
	end;

end.
